#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

from socket import socket, AF_INET, SOCK_STREAM
from scheculer import Scheduler, ReadWait, WriteWait

def time_server(address):
  import time
  s = socket(AF_INET, SOCK_STREAM)
  s.bind(address)
  s.listen(5)
  
  while True:
    yield ReadWait(s)
    conn, addr = s.accept()
    print("Connection from %s" % str(addr))
    yield WriteWait(conn)
    resp = time.ctime() + "\r\n"
    conn.send(resp.encode('latin-1'))
    conn.close()
    
sched = Scheduler()
sched.new(time_server(('', 10000)))
sched.new(time_server(('', 11000)))
sched.run()
